package org.linlinjava.litemall.admin.web.order_manage;

import org.linlinjava.litemall.admin.constant.HeaderConstant;
import org.linlinjava.litemall.admin.form.StoreAddForm;
import org.linlinjava.litemall.admin.form.StoreListForm;
import org.linlinjava.litemall.admin.service.order_manage.AgedmallShopStoreService;
import org.linlinjava.litemall.admin.vo.shop.CreateShopVo;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/shop/store")
public class AgedmallShopStoreController {

    @Autowired
    private AgedmallShopStoreService agedmallShopStoreService;

    /**
     * 获取门店列表
     */
    @PostMapping("/storeList")
    public Object storeList(@RequestBody @Validated StoreListForm storeListForm, HttpServletRequest request){
        Integer busiId = request.getIntHeader(HeaderConstant.HEADER_BUSIID);
        if (busiId == -1) {
            return ResponseUtil.unauthz();
        }
        return agedmallShopStoreService.storeList(busiId, storeListForm);
    }

    /**
     * 添加门店
     */
    @PostMapping("/addStore")
    public Object addStore(@RequestBody @Validated StoreAddForm storeAddForm, HttpServletRequest request){
        Integer busiId = request.getIntHeader(HeaderConstant.HEADER_BUSIID);
        if (busiId == -1) {
            return ResponseUtil.unauthz();
        }
        return agedmallShopStoreService.addStore(busiId, storeAddForm);
    }

    /**
     * 门店删除
     */
    @PostMapping("/delStore")
    public Object delStore(@RequestParam List<Long> storeIds){
        return agedmallShopStoreService.delStore(storeIds);
    }

    /**
     * 门店详情
     */
    @PostMapping("/storeDetail")
    public Object storeDetail(@RequestParam Long storeId){
        return agedmallShopStoreService.storeDetail(storeId);
    }

    /**
     * 门店详情-获取商品列表
     */
    @PostMapping("/commodityDetail/list")
    public Object commodityDetailList(@RequestParam Long storeId,
                                      @RequestParam(required = false) String state,
                                      @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer limit){
        return agedmallShopStoreService.commodityDetailList(storeId, state, page, limit);
    }

    /**
     * 门店详情-添加商品-列表
     */
    @PostMapping("/commodityDetail/addDialogList")
    public Object commodityDetailAddDialogList(@RequestParam(required = false) String classIfication1,
                                                @RequestParam(required = false) String classIfication2,
                                                @RequestParam(required = false) String type,
                                                @RequestParam(required = false) String keySearch,
                                                @RequestParam(defaultValue = "1") Integer page,
                                                @RequestParam(defaultValue = "10") Integer limit, HttpServletRequest request){
        Integer busiId = request.getIntHeader(HeaderConstant.HEADER_BUSIID);
        if (busiId == -1) {
            return ResponseUtil.unauthz();
        }
        return agedmallShopStoreService.commodityDetailAddDialogList(busiId, classIfication1, classIfication2, type, keySearch, page, limit);
    }

    /**
     * 门店详情-取消运营
     */
    @PostMapping("/commodityDetail/cancel")
    public Object commodityDetailCancel(@RequestParam List<Long> storeGoodsIds){
        return agedmallShopStoreService.commodityDetailCancel(storeGoodsIds);
    }

    /**
     * 门店详情-运维费管理
     */
    @PostMapping("/commodityDetail/setting")
    public Object commodityDetailSetting(@RequestParam Long storeGoodsId, @RequestParam Long maintainTemplateId){
        return agedmallShopStoreService.commodityDetailSetting(storeGoodsId, maintainTemplateId);
    }

    /**
     * 门店详情-RFID设备
     */
    @PostMapping("/commodityDetail/equipment")
    public Object commodityDetailEquipment(@RequestParam Long storeId,
                                               @RequestParam Long goodsProductId,
                                               @RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10") Integer limit){
        return agedmallShopStoreService.commodityDetailEquipment(storeId, goodsProductId, page, limit);
    }

    /**
     * RFID设备-商品-RFID设备-查看详情
     */
    @PostMapping("/commodityDetail/equipmentDetail")
    public Object commodityDetailEquipmentDetail(@RequestParam Long equipmentId,
                                           @RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer limit){
        return agedmallShopStoreService.commodityDetailEquipmentDetail(equipmentId, page, limit);
    }

    /**
     * 门店详情-删除员工
     */
    @PostMapping("/employee/del")
    public Object employeeDel(@RequestParam String storeId, @RequestParam List<Integer> staffIds){
        return agedmallShopStoreService.employeeDel(storeId, staffIds);
    }

    /**
     * 门店详情-根据商品id获取运维模费板
     */
    @GetMapping("/commodityDetail/getSetting")
    public Object commodityDetailGetSetting(@RequestParam Integer storeGoodsId){
        return agedmallShopStoreService.commodityDetailGetSetting(storeGoodsId);
    }
}
